package com.pzh.vue.controller;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Quarter;
import com.pzh.vue.common.Result;
import com.pzh.vue.pojo.SysUser;
import com.pzh.vue.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/echart")
public class EchartsController {
    @Autowired
    private SysUserService sysUserService;
    @GetMapping("/members")
    public Result members(){
        List<SysUser> list=sysUserService.list();
        int month1=0;
        int month2=0;
        int month3=0;
        int month4=0;
        for (SysUser user:list){
            Date createTime = user.getCreateTime();
            Quarter quarter = DateUtil.quarterEnum(createTime);
            switch (quarter){
                case Q1:month1+=1;break;
                case Q2:month2+=1;break;
                case Q3:month3+=1;break;
                case Q4:month4+=1;break;
                default:break;
            }
        }
        return Result.success(CollUtil.newArrayList(month1,month2,month3,month4));
    }
}
